package com.example.redis.demos.web.Redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-07-13
 * Time:9:37
 * Text：
 */
public class Redis_String {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("120.46.91.1",6379);
        try(Jedis jedis = jedisPool.getResource()){
            jedis.auth("2287448684t");
            Test4(jedis);
        }
    }

    private static void Test1(Jedis jedis) {
        System.out.println("mset  |  mget");
        jedis.flushAll();

        jedis.mset("key1","111","key2","222","key3","333");
        List<String> list = jedis.mget("key1","key2","key3");
        System.out.println(list);
    }
    public static void Test2(Jedis jedis){
        System.out.println("getrange | setrange");

        jedis.flushAll();

        jedis.set("key","123456789");
        String result = jedis.getrange("key",2,5);
        System.out.println(result);

        jedis.setrange("key",2,"333");
        System.out.println(jedis.get("key"));
    }
    public static  void Test3(Jedis jedis){
        System.out.println("append");
        jedis.flushAll();

        jedis.set("key","1234");
        jedis.append("key","abcd");
        System.out.println(jedis.get("key"));
    }
    public static void Test4(Jedis jedis){
        System.out.println("incr | decr");
        jedis.flushAll();

        jedis.set("key","100");
        System.out.println(jedis.incr("key"));
        System.out.println(jedis.decr("key"));
    }
}
